/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ejecucion;

import javax.mail.*; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 
import java.util.Properties; 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
/**
 *
 * @author dcoto
 */
public class Correo {
    public static void enviar(String mail) { 
        Correo obj = new Correo(); 
        String server = "smtp.gmail.com"; 
        String userName = "reportes.hades@gmail.com"; 
        String password = "ihades2011"; 
        String fromAddres = "reportes.hades@gmail.com"; 
        String toAddres = mail;  

        String cc = ""; 
        String bcc = ""; 
        boolean htmlFormat = false; 
        String subject="";
        
        subject = "Su empresa ha sido habilitada en tuJob.!!!";
        
        String body = "Felicidades, ya puede ingresar las vacantes para su empresa!!!"; 
         
        obj.sendMail(server, userName, password, fromAddres, toAddres, cc, bcc, htmlFormat, subject, body); 
         
    } 

    public void sendMail(String server, String userName, String password, String fromAddress, String toAddress, String cc, String bcc, boolean htmlFormat, String subject, String body) 
    { 
     
        Properties properties = System.getProperties(); 
        properties.put("mail.smtps.host", server); 
        properties.put("mail.smtps.port", "465"); 
        properties.put("mail.smtps.auth", "true"); 
        Session ses  = Session.getInstance(properties); 


        ses.setDebug(true); 

        try{ 
            MimeMultipart multiParte = new MimeMultipart();
            
         MimeMessage msg = new MimeMessage(ses); 
         MimeBodyPart textPart = new MimeBodyPart();
         textPart.setContent("<h1>Felicidades, ya puede ingresar las vacantes para su empresa!!!</h1>", "text/html");
         multiParte.addBodyPart(textPart);
            msg.setFrom(new InternetAddress(fromAddress)); 
     
            if (toAddress != null) 
            { 
               msg.addRecipients(Message.RecipientType.TO, toAddress); 
            } 
     
            if (cc != null) 
            { 
                msg.setRecipients(Message.RecipientType.CC 
                        ,InternetAddress.parse(cc, false)); 
            } 
     
            if (bcc != null) 
            { 
                msg.setRecipients(Message.RecipientType.BCC 
                        ,InternetAddress.parse(bcc, false)); 
            } 
     
            if (htmlFormat) 
            { 
                msg.setContent("This is a test", "text/plain"); 
                
                
            } 
            else 
            { 
                msg.setContent(body, "text/plain"); 
                msg.setContent(multiParte);
            } 
     
            msg.setSubject(subject); 
            msg.saveChanges(); 
     
            Transport tr = ses.getTransport("smtps"); 
            tr.connect(server,userName, password); 
            tr.sendMessage(msg, msg.getAllRecipients()); 
            tr.close(); 
        } 
         
        catch(MessagingException e) 
        { 
            e.printStackTrace(); 
        } 
         
         

    } 
}
